//
//  NSObject+ProgressHUD.m
//  YSProgressHUD
//
//  Created by 李雪健 on 2021/8/16.
//

#import "NSObject+ProgressHUD.h"
#import "MBProgressHUD.h"

@implementation NSObject (ProgressHUD)

+ (void)ys_showHint:(NSString *)hint {
    
    [self ys_showHint:hint afterDelay:2.0f];
}

+ (void)ys_showHint:(NSString *)hint afterDelay:(CGFloat)afterDelay {
    
    if (hint && [hint isKindOfClass:[NSString class]] && hint.length >0) {
        
        MBProgressHUD *hud  = [[MBProgressHUD alloc] init];
        [[[UIApplication sharedApplication].delegate window] addSubview:hud];
        /// 修改样式，否则等待框背景色将为半透明
        hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
        /// 设置等待框背景色为黑色
        hud.bezelView.backgroundColor = [UIColor blackColor];
        hud.mode = MBProgressHUDModeText;
        hud.removeFromSuperViewOnHide = YES;
        if (hint != nil && hint.length > 0) {
            hud.detailsLabel.font = [UIFont systemFontOfSize:15];
            hud.detailsLabel.text = hint;
            hud.detailsLabel.textColor = [UIColor whiteColor];
        }
        [hud showAnimated:YES];
        [hud hideAnimated:YES afterDelay:afterDelay];
    }
}

+ (void)ys_showLoading {
    
    [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
}

+ (void)ys_hiddenLoading {
    
    [MBProgressHUD hideHUDForView:[UIApplication sharedApplication].delegate.window animated:YES];
}

@end
